package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.THospital;
import com.ruoyi.system.service.ITHospitalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医院信息Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@RestController
@RequestMapping("/system/hospital")
public class THospitalController extends BaseController
{
    @Autowired
    private ITHospitalService tHospitalService;

    /**
     * 查询医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(THospital tHospital)
    {
        startPage();
        List<THospital> list = tHospitalService.selectTHospitalList(tHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:hospital:export')")
    @Log(title = "医院信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(THospital tHospital)
    {
        List<THospital> list = tHospitalService.selectTHospitalList(tHospital);
        ExcelUtil<THospital> util = new ExcelUtil<THospital>(THospital.class);
        return util.exportExcel(list, "hospital");
    }

    /**
     * 获取医院信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:hospital:query')")
    @GetMapping(value = "/{hid}")
    public AjaxResult getInfo(@PathVariable("hid") Long hid)
    {
        return AjaxResult.success(tHospitalService.selectTHospitalById(hid));
    }

    /**
     * 新增医院信息
     */
    @PreAuthorize("@ss.hasPermi('system:hospital:add')")
    @Log(title = "医院信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody THospital tHospital)
    {
        return toAjax(tHospitalService.insertTHospital(tHospital));
    }

    /**
     * 修改医院信息
     */
    @PreAuthorize("@ss.hasPermi('system:hospital:edit')")
    @Log(title = "医院信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody THospital tHospital)
    {
        return toAjax(tHospitalService.updateTHospital(tHospital));
    }

    /**
     * 删除医院信息
     */
    @PreAuthorize("@ss.hasPermi('system:hospital:remove')")
    @Log(title = "医院信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hids}")
    public AjaxResult remove(@PathVariable Long[] hids)
    {
        return toAjax(tHospitalService.deleteTHospitalByIds(hids));
    }
}
